$import( "SmitearWebGL.Objects.Canvas.ScreenQuad" );
$import( "SmitearWebGL.Programs.LightPrePass.SSAOProgram" );

SmitearWebGL.Objects.Canvas.LightPrePass.SSAO = SmitearWebGL.Objects.Canvas.ScreenQuad.extend(
{
	/******** constructor ********/

	init : function()
	{
		this._super();
		this._registClass( "SmitearWebGL.Objects.Canvas.LightPrePass.SSAO" );
		
		this._ssaoTech = null;
	}
	,
	
	//override render function
	renderCallBack : function( renderSession )
	{
		if ( ! SmitearWebGL.Scene._ssaoEnable )
			return SmitearWebGL.Core.HResult.SUCCESS;
		
		var program = this._ssaoTech;
		
		var hr = SmitearWebGL.Core.HResult.SUCCESS;

		hr |= program.activeShader();
		hr |= program.activeUniform( renderSession, this );
			
		hr |= this._vertexBuffer.bind();
		hr |= this._vertexBuffer.active( program.getShader() );
		
		this.context.gl.drawArrays( this.context.gl.TRIANGLE_STRIP, 0, 4 );
		
		return hr;
	}
	,
	_createResource : function( params )
	{
		this._super();
		
		this._ssaoTech = this.context.programManager.getResourceByName( SmitearWebGL.Programs.InternalPrograms.Type.LP_SSAO );
	}
	,
	_destroyResource : function()
	{
		this._super();
		
		this._ssaoTech = null;
	}
}
);
